package com.shawn.spring.boot.redis.converter;

import java.nio.charset.StandardCharsets;
import org.joda.money.Money;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.WritingConverter;

/**
 * @author shawn
 * @since 2020/9/4
 */
@WritingConverter
public class MoneyToBytesConverter implements Converter<Money, byte[]> {
  @Override
  public byte[] convert(Money source) {
    String value = Long.toString(source.getAmountMinorLong());
    return value.getBytes(StandardCharsets.UTF_8);
  }
}
